import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class MouseDemo extends Applet implements MouseListener {
    BlankArea blankArea;
    TextArea textArea;
    static final int maxInt = java.lang.Integer.MAX_VALUE;
    public void init() {
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	setLayout(gridbag);

	c.fill = GridBagConstraints.BOTH;
	c.gridwidth = GridBagConstraints.REMAINDER;
	c.weightx = 1.0;
	c.weighty = 1.0;

	c.insets = new Insets(1, 1, 1, 1);
	blankArea = new BlankArea();
	gridbag.setConstraints(blankArea, c);
	add(blankArea);

	c.insets = new Insets(0, 0, 0, 0);
	textArea = new TextArea(5, 20);
	textArea.setEditable(false);
	gridbag.setConstraints(textArea, c);
	add(textArea);

	blankArea.addMouseListener(this);
	addMouseListener(this);
			       
    }
    public void mousePressed(MouseEvent e) {
	saySomething("Mouse button press", e);
    }
    public void mouseReleased(MouseEvent e) {
	saySomething("Mouse button release", e);
    }
    public void mouseEntered(MouseEvent e) {
	saySomething("Cursor enter", e);
    }
    public void mouseExited(MouseEvent e) {
	saySomething("Cursor exit", e);
    }
    public void mouseClicked(MouseEvent e) {
	saySomething("Mouse button click", e);
    }
    void saySomething(String eventDescription, MouseEvent e) {
	textArea.append(eventDescription + "detected on" + e.getComponent().getClass().getName() + ". \n");
	textArea.setCaretPosition(maxInt);
    }
}
class BlankArea extends Canvas {
    Dimension minSize = new Dimension(100, 100);
    public Dimension getMinimumSize() {
	return minSize;
    }
    public Dimension getPreferedSize() {
	return minSize;
    }
    public void paint(Graphics g) {
	Dimension size = getSize();
	g.drawRect(0, 0, size.width - 1, size.height - 1);
    }
}
